package com.wisezone.demo0304;

import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MyResult implements ResultSetHandler<List<Result>> {
    @Override
    public List<Result> handle(ResultSet resultSet) throws SQLException {
        Result result;
        List<Result> results=null;
        if(resultSet!=null){
            results=new ArrayList<>();
            String colName;
            while (resultSet.next()){
                int count =resultSet.getMetaData().getColumnCount();
                for(int i=1;i<count;i++){
                    colName=resultSet.getMetaData().getColumnLabel(i);
                    System.out.println(colName);
                }

                result=new Result();
                result.setStudentNo(resultSet.getInt(1));
                result.setSubjectNo(resultSet.getInt(2));
                result.setExamDate(resultSet.getTimestamp(3));
                result.setStudentResult(resultSet.getInt(4));
                results.add(result);
            }
        }
        return results;
    }
}
